package com.example.manu_facturer_orders.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.manu_facturer_orders.mapper.ServiceProviderMapper;
import com.example.manu_facturer_orders.pojo.EnginnerVO;
import com.example.manu_facturer_orders.pojo.ServiceProviderVO;
import com.example.manu_facturer_orders.service.ServiceProviderService;
import commons.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @author: tobed
 * @date: 2022/9/13
 * @time: 16:58
 */
@Service
public class ServiceProviderServiceImpl implements ServiceProviderService {

    @Autowired
    ServiceProviderMapper serviceProviderMapper;

    /**
     * 服务商全查
     * @param facilitatorCode
     * @param facilitatorName
     * @param signingType
     * @return
     */
    @Override
    public Page<ServiceProviderVO> list(String facilitatorCode, String facilitatorName, Integer signingType, Page<ServiceProviderVO> page) {
        Page<ServiceProviderVO> list = serviceProviderMapper.list(facilitatorCode,facilitatorName,signingType,page);
        return list;
    }

    /**
     * 服务商解约
     * @param id
     * @return
     */
    @Override
    public Result terminationService(Integer id) {
        int i = serviceProviderMapper.terminationService(id);
        if (i!=0){
            return Result.success();
        }else{
            return Result.error();
        }
    }

    /**
     * 启用或停用服务商
     * @param id
     * @param signingType
     * @return
     */
    @Override
    public Result openOrClose(Integer id, Integer signingType) {
        int type = -1;
        if (signingType.equals(2)){
            type = 1;
        }
        if (signingType.equals(1)){
            type = 2;
        }
        int i = serviceProviderMapper.openOrClose(id,type);
        if (i!=0){
            return Result.success();
        }else{
            return Result.error();
        }
    }
}
